package com.hnkywl.sts.service.djgl;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.hnkywl.sts.dao.djgl.DjcxDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Date;
import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: Administrator
 * Date: 13-6-14
 * Time: 下午4:50
 * To change this template use File | Settings | File Templates.
 */
@Service
public class DjcxService {
    private DjcxDao djcxDao;

    public String djcxList(String dhhm, Date djcxStart, Date djcxEnd, Integer pageNo, Integer pageSize) {
        Map<String, Object> result = djcxDao.djcxList(dhhm, djcxStart, djcxEnd, pageNo, pageSize);
        List<Map> rows = (List<Map>) result.get("rows");
        List<Map> footer = (List<Map>) result.get("footer");
        Gson gson = new GsonBuilder().create();
        String footerJson = gson.toJson(footer);
        String rowsJson = gson.toJson(rows);
        String json = "{\"rows\":" + rowsJson + ",\"footer\":" + footerJson + "}";
        return json;
    }


    @Autowired
    public void setDjcxDao(DjcxDao djcxDao) {
        this.djcxDao = djcxDao;
    }
}
